﻿@namespace BootstrapBlazor.Components
@inherits ComponentBase
@typeparam Model

<FormViewer FilterProperties=FilterProperties ToPropertyInfo=ToPropertyInfo
            Verify=Verify InitializationModel="InitializationModel"
            ExistingForms=ExistingForms IsReadOnly=IsReadOnly
            OnPropertyChangeed=OnPropertyChangeed ShowSubmit=ShowSubmit
            IsValueReference=IsValueReference>
    <ChildContent>
        @if (ChildContent is null)
        {
            <div class="bootstrapFormViewerContainer">
                @context.RenderMain
                <div />
                @context.RenderSubmit
            </div>
        }
        else
        {
            @ChildContent(context)
        }
    </ChildContent>
    <RenderMain>
        @if (RenderMain is null)
        {
            <div class="bootstrapFormViewerContainer">
                @foreach (var item in context)
                {
                    @item.Render
                }
            </div>
        }
        else
        {
            @RenderMain(context)
        }
    </RenderMain>
    <RenderProperty>
        @if (RenderProperty is null)
        {
            <BootstrapFormViewerProperty RenderInfo="context" />
        }
        else
        {
            @RenderProperty(context)
        }
    </RenderProperty>
    <RenderSubmit>
        @{
            var newInfo = GetRenderSubmitInfo(context);
        }
        @if (RenderSubmit is null)
        {
            <CompactCentered>
                <Button Text="@(context.ExistingForms?"修改":"提交")" OnClick="newInfo.Submit"></Button>
                <Button Text="重置" OnClick="newInfo.Resetting"></Button>
                @if (newInfo.Delete is { } deleteValue)
                {
                    <Button Text="删除" OnClick="deleteValue"></Button>
                }
                @if (newInfo.Cancellation is { } cancellationValue)
                {
                    <Button Text="取消" OnClick="cancellationValue"></Button>
                }
            </CompactCentered>
        }
        else
        {
            @RenderSubmit(newInfo)
        }
    </RenderSubmit>
</FormViewer>